package net.htjs.mobile.qxoa.gw;

import android.R.color;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.Window;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.LinearLayout.LayoutParams;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.TextView;

public class GwList extends Activity implements
		RadioGroup.OnCheckedChangeListener, OnClickListener {
	private TextView mChoice;
	private RadioGroup mRadioGroup;
	private Button clearButton;
	private View v;
	private LinearLayout layout;
	private final int id1 = 10000000;
	private final int id2 = 20000000;

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		requestWindowFeature(Window.FEATURE_NO_TITLE);

		layout = new LinearLayout(this);
		layout.setOrientation(LinearLayout.VERTICAL);
		LinearLayout.LayoutParams lps = new LinearLayout.LayoutParams(
				LinearLayout.LayoutParams.MATCH_PARENT,
				LinearLayout.LayoutParams.WRAP_CONTENT);
		layout.setLayoutParams(lps);
		mRadioGroup = new RadioGroup(this);
		// 添加一个单选按钮
		RadioButton newRadioButton = new RadioButton(this);
		newRadioButton.setText("the first button");
		newRadioButton.setId(this.id1);
		RadioGroup.LayoutParams layoutParams = new RadioGroup.LayoutParams(
				RadioGroup.LayoutParams.WRAP_CONTENT,
				RadioGroup.LayoutParams.WRAP_CONTENT);
		mRadioGroup.addView(newRadioButton, 0, layoutParams);

		// 画一条线
		v = new View(this);
		v.setBackgroundColor(color.darker_gray);
		v.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, 2));

		RadioButton newRadioButton2 = new RadioButton(this);
		newRadioButton2.setId(this.id2);
		newRadioButton2.setText("the second button");
		RadioGroup.LayoutParams layoutParams2 = new RadioGroup.LayoutParams(
				RadioGroup.LayoutParams.WRAP_CONTENT,
				RadioGroup.LayoutParams.WRAP_CONTENT);
		mRadioGroup.addView(newRadioButton2, 1, layoutParams2);
		mRadioGroup.setOnCheckedChangeListener(this);
		mChoice = new TextView(this);
		ViewGroup.LayoutParams ltp = new ViewGroup.LayoutParams(
				ViewGroup.LayoutParams.WRAP_CONTENT,
				ViewGroup.LayoutParams.WRAP_CONTENT);
		mChoice.setLayoutParams(ltp);
		mChoice.setPadding(0, 20, 0, 0);
		mChoice.setText("请选择");

		clearButton = new Button(this);
		// 重用上面的layout参数
		ViewGroup.LayoutParams lbt = new ViewGroup.LayoutParams(ltp);
		clearButton.setLayoutParams(lbt);
		clearButton.setText("清除选中状态");

		clearButton.setOnClickListener(this);

		layout.addView(mRadioGroup);
		layout.addView(mChoice);
		layout.addView(clearButton);
		setContentView(layout);
	}

	public void onCheckedChanged(RadioGroup group, int checkedId) {

		mChoice.setText("你选择的button的id是："
				+ (checkedId == View.NO_ID ? "none" : checkedId));
	}

	public void onClick(View v) {
		// TODO Auto-generated method stub
		mRadioGroup.clearCheck();
	}
}